﻿package mortal.game.view.lookPlayerInfo.view
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import baseEngine.system.*;
    import com.mui.controls.*;
    import flash.geom.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.view.common.*;
    import mortal.game.view.palyer.item.*;

    public class LookPlayerHalidomPanel extends GSprite
    {
        private var _hImg2D:Img2D;
        private var _hIm:GImageBitmap;
        public var rect3d:Rect3DObject;
        private var _cellArr:Array;
        private var _isLoad:Boolean = false;
        private var _halidomMod:UserModelPlayer;
        private var _slookPlayerInfo:SLookPlayerInfo;
        private var _visib:Boolean = true;
        public static var posArr:Array = [new Point(213 - 5, 130 - 32), new Point(46 - 5, 163 - 32), new Point(355 - 5, 183 - 32), new Point(92 - 5, 255 - 32), new Point(322 - 5, 281 - 32), new Point(59 - 5, 373 - 32), new Point(382 - 5, 362 - 32), new Point(320 - 5, 452 - 32)];

        public function LookPlayerHalidomPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._isLoad = false;
            return;
        }// end function

        public function init3DMd(param1:Rect3DObject) : void
        {
            var _loc_2:ItemEquipInfo = null;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_8:SPlayerItem = null;
            var _loc_9:int = 0;
            var _loc_10:int = 0;
            var _loc_11:int = 0;
            this.rect3d = param1;
            var _loc_7:* = this._slookPlayerInfo.miniPlayer.VIP;
            for each (_loc_8 in this._slookPlayerInfo.playerItems)
            {
                
                _loc_2 = ItemConfig.instance.getConfig(_loc_8.itemCode) as ItemEquipInfo;
                if (_loc_2.type == EEquip._EEquipWeaponFashion)
                {
                    _loc_4 = int(_loc_2.modelId);
                    continue;
                }
                if (_loc_3 == 0 && _loc_2.type == EEquip._EEquipClothes)
                {
                    _loc_3 = int(_loc_2.modelId);
                    continue;
                }
                if (_loc_4 == 0 && _loc_2.type == EEquip._EEquipWeapon)
                {
                    _loc_4 = int(_loc_2.modelId);
                    continue;
                }
                if (_loc_2.type == EEquip._EEquipHeadwear)
                {
                    _loc_6 = int(_loc_2.modelId);
                }
            }
            _loc_9 = this.getClothesModelId();
            _loc_10 = this.getWingModelId();
            _loc_11 = this.getWeaponModelId();
            if (_loc_9 > 0)
            {
                _loc_3 = _loc_9;
            }
            if (_loc_10 > 0)
            {
                _loc_5 = _loc_10;
            }
            if (_loc_11 > 0)
            {
                _loc_4 = _loc_11;
            }
            if (this._halidomMod == null)
            {
                this._halidomMod = FrObjectPool.getObject(UserModelPlayer, this);
            }
            this._halidomMod.updateInfo(this._slookPlayerInfo.miniPlayer.career, this._slookPlayerInfo.miniPlayer.sex, _loc_3, _loc_4, _loc_6, _loc_5, _loc_7);
            this._halidomMod.scaleAll = 2.2;
            this._halidomMod.setRenderList(this.rect3d.renderList);
            this._halidomMod.useLight();
            this._halidomMod.rotationY = 0;
            this.rect3d.addObject3d(this._halidomMod, 250, 450);
            this._halidomMod.removedFromScene();
            this._hIm = UIFactory.gImageBitmap(ImagesConst.RoleHalidomBg, 0, -28, null, this.onResLoad);
            return;
        }// end function

        private function getClothesModelId() : int
        {
            var _loc_1:int = 0;
            var _loc_2:ItemEquipInfo = null;
            var _loc_3:TMountConfig = null;
            if (this._slookPlayerInfo.clothesCode > 10000)
            {
                _loc_2 = ItemConfig.instance.getConfig(this._slookPlayerInfo.clothesCode) as ItemEquipInfo;
                _loc_1 = _loc_2 ? (_loc_2.modelId) : (0);
            }
            else
            {
                _loc_3 = MountConfig.instance.getFashionInfoByCode(EAdvanceComponentType._EAdvanceComponentTypeClothes, this._slookPlayerInfo.clothesCode);
                _loc_1 = _loc_3 ? (_loc_3.modelId) : (0);
            }
            return _loc_1;
        }// end function

        private function getWingModelId() : int
        {
            var _loc_1:int = 0;
            var _loc_2:ItemEquipInfo = null;
            var _loc_3:TMountConfig = null;
            if (this._slookPlayerInfo.wingCode > 10000)
            {
                _loc_2 = ItemConfig.instance.getConfig(this._slookPlayerInfo.wingCode) as ItemEquipInfo;
                _loc_1 = _loc_2 ? (_loc_2.modelId) : (0);
            }
            else
            {
                _loc_3 = MountConfig.instance.getFashionInfoByCode(EAdvanceComponentType._EAdvanceComponentTypeWing, this._slookPlayerInfo.wingCode);
                _loc_1 = _loc_3 ? (_loc_3.modelId) : (0);
            }
            return _loc_1;
        }// end function

        private function getWeaponModelId() : int
        {
            var _loc_1:int = 0;
            var _loc_2:ItemEquipInfo = null;
            var _loc_3:TMountConfig = null;
            if (this._slookPlayerInfo.weaponCode > 10000)
            {
                _loc_2 = ItemConfig.instance.getConfig(this._slookPlayerInfo.weaponCode) as ItemEquipInfo;
                _loc_1 = _loc_2 ? (_loc_2.modelId) : (0);
            }
            else
            {
                _loc_3 = MountConfig.instance.getFashionInfoByCode(EAdvanceComponentType._EAdvanceComponentTypeWing, this._slookPlayerInfo.weaponCode);
                _loc_1 = _loc_3 ? (_loc_3.modelId) : (0);
            }
            return _loc_1;
        }// end function

        public function set data(param1:SLookPlayerInfo) : void
        {
            this._slookPlayerInfo = param1;
            return;
        }// end function

        private function onResLoad() : void
        {
            if (isDisposed || this.rect3d == null || this._isLoad == true)
            {
                return;
            }
            this._isLoad = true;
            if (this.rect3d && this._hImg2D)
            {
                this.rect3d.removeImg(this._hImg2D);
                this._hImg2D.dispose();
                this._hImg2D = null;
            }
            this._hImg2D = new Img2D(null, this._hIm.bitmapData, new Rectangle(0, 0, 490, 546), true);
            this._hImg2D.x = 0;
            this._hImg2D.y = 0;
            this.rect3d.addImg(this._hImg2D);
            this.genCells();
            this.updateAllEquip();
            this.visible = this._visib;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._isLoad = false;
            this._visib = false;
            if (this.rect3d && this._hImg2D)
            {
                this.rect3d.removeImg(this._hImg2D);
                this._hImg2D.dispose();
                this._hImg2D = null;
            }
            if (this.rect3d)
            {
                this.rect3d.disposeObj3d(this._halidomMod);
                this._halidomMod = null;
            }
            this.clearCells();
            this.rect3d = null;
            this._slookPlayerInfo = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function genCells() : void
        {
            var _loc_2:RoleHalidomCell = null;
            this._cellArr = [];
            var _loc_1:int = 0;
            while (_loc_1 < 8)
            {
                
                _loc_2 = UIFactory.getUICompoment(RoleHalidomCell);
                _loc_2.rect3d = this.rect3d;
                _loc_2.pos = posArr[_loc_1];
                _loc_2.updateName(_loc_1);
                this.addChild(_loc_2);
                this._cellArr.push(_loc_2);
                _loc_1++;
            }
            return;
        }// end function

        private function clearCells() : void
        {
            var _loc_2:RoleHalidomCell = null;
            if (this._cellArr == null)
            {
                return;
            }
            var _loc_1:int = 0;
            while (_loc_1 < this._cellArr.length)
            {
                
                _loc_2 = this._cellArr[_loc_1];
                _loc_2.dispose();
                _loc_1++;
            }
            this._cellArr = null;
            return;
        }// end function

        private function updateAllEquip() : void
        {
            var _loc_1:* = this._cellArr.length;
            var _loc_2:int = 0;
            while (_loc_2 < _loc_1)
            {
                
                this.updateEquipByType(_loc_2);
                _loc_2++;
            }
            return;
        }// end function

        private function getItemByType(param1:int) : ItemData
        {
            var _loc_2:ItemData = null;
            var _loc_3:ItemData = null;
            var _loc_4:SPlayerItem = null;
            for each (_loc_4 in this._slookPlayerInfo.godHeads)
            {
                
                _loc_2 = new ItemData(_loc_4);
                if (_loc_2.itemInfo.type == param1)
                {
                    _loc_3 = _loc_2;
                    break;
                }
            }
            return _loc_3;
        }// end function

        public function updateEquipByType(param1:int) : void
        {
            var _loc_5:int = 0;
            if (param1 < 0 || param1 > this._cellArr.length)
            {
                return;
            }
            var _loc_2:* = RoleHalidomPanel.mappingTypeToIndex(param1);
            var _loc_3:* = this._cellArr[_loc_2];
            var _loc_4:* = this.getItemByType(param1);
            _loc_3.clearCell();
            if (_loc_4)
            {
                _loc_3.item.itemData = _loc_4;
                _loc_3.updateInfo(param1);
                _loc_3.colorScreen = false;
                _loc_3.item.buttonMode = true;
            }
            else
            {
                _loc_5 = RoleHalidomPanel.mappingTypeToItemCode(param1);
                _loc_4 = new ItemData(_loc_5);
                _loc_3.item.itemData = _loc_4;
                _loc_3.updateInfo(param1);
                _loc_3.colorScreen = true;
                _loc_3.item.buttonMode = false;
            }
            return;
        }// end function

        override public function set visible(param1:Boolean) : void
        {
            var _loc_2:int = 0;
            var _loc_3:RoleHalidomCell = null;
            super.visible = param1;
            this._visib = param1;
            if (this._isLoad == false)
            {
                return;
            }
            if (this._hImg2D == null)
            {
                return;
            }
            if (param1)
            {
                if (this._hImg2D.scene == null)
                {
                    this._hImg2D.addedToScene(Global3D.scene);
                }
                this._halidomMod.addedToScene(Global3D.scene);
            }
            else
            {
                this._halidomMod.removedFromScene();
            }
            if (this._cellArr)
            {
                _loc_2 = 0;
                while (_loc_2 < this._cellArr.length)
                {
                    
                    _loc_3 = this._cellArr[_loc_2];
                    _loc_3.visible = param1;
                    _loc_2++;
                }
            }
            return;
        }// end function

    }
}
